home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / FSEL_INP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-22  |  4.1 KB  |  212 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <OSBIND.H>
  9. #include <MINTBIND.H>
  10. #include <SIGNAL.H>
  11. #include <FILESYS.H>
  12. #include <VDI.H>
  13. #include <unistd.h>            /* getcwd() */
  14. #include <stdlib.h>            /* free() */
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <limits.h>            /* PATH/NAME_MAX */
  18. #include "XA_TYPES.H"
  19. #include "XA_DEFS.H"
  20. #include "XA_GLOBL.H"
  21. #include "K_DEFS.H"
  22. #include "FSELECT.H"
  23.  
  24. XA_CLIENT *fsel_owner;
  25. AESPB *fsel_pb;
  26.  
  27. void handle_fsel(char *path,char *file)
  28. {
  29.     unsigned long rtn=XAC_DONE;
  30.     char *t;
  31.  
  32.     for(t=path; *t; t++)
  33.     {
  34.         if(*t=='/')
  35.             *t='\\';
  36.     }
  37.  
  38.     if (path[0]!='u')
  39.         sprintf((char*)fsel_pb->addrin[0],"u:%s\\",path);
  40.     else
  41.         sprintf((char*)fsel_pb->addrin[0],"%s\\",path);
  42.         
  43.     strcpy((char*)fsel_pb->addrin[1],file);
  44.  
  45.     DIAGS(("handle_fsel:path=%s,file=%s\n",(char*)fsel_pb->addrin[0],file));
  46.     
  47.     fsel_pb->intout[0]=1;
  48.     fsel_pb->intout[1]=1;
  49.     
  50.     Fwrite(fsel_owner->clnt_pipe_wr,sizeof(unsigned long),&rtn);
  51. }
  52.  
  53. void cancel_fsel(char *path, char *file)
  54. {
  55.     unsigned long rtn=XAC_DONE;
  56.     
  57.     fsel_pb->intout[0]=1;
  58.     fsel_pb->intout[1]=0;
  59.  
  60.     Fwrite(fsel_owner->clnt_pipe_wr,sizeof(unsigned long),&rtn);
  61. }
  62.  
  63. /*
  64.     File selector interface routines
  65. */
  66. unsigned long XA_fsel_input(short clnt_pid, AESPB *pb)
  67. {
  68.     XA_CLIENT *client=Pid2Client(clnt_pid);
  69.     char *t;
  70.     unsigned long dummy_rtn;
  71.  
  72. /* Loads of programs lock the screen and the mouse before doing fsel_
  73.    so we've got to unlock them again to allow the XaAES windowed file selector
  74.    to work.
  75. */
  76.     
  77.     if (update_lock==clnt_pid)
  78.     {
  79.         update_cnt=0;
  80.         update_lock=FALSE;
  81.         Psemaphore(3,UPDATE_LOCK,0L);
  82.     }
  83.  
  84.     if (mouse_lock==clnt_pid)
  85.     {
  86.         mouse_cnt=0;
  87.         mouse_lock=FALSE;
  88.         Psemaphore(3,MOUSE_LOCK,0L);
  89.     }
  90.  
  91.     Psemaphore(2,FSELECT_SEMAPHORE,-1L);    /* Wait for access to the fileselector */    
  92.  
  93.     DIAGS(("fsel_input:path=%s,file=%s\n",(char*)pb->addrin[0],(char*)pb->addrin[1]));
  94.  
  95.     t=(char*)pb->addrin[0];
  96.     if((t[0]|32)!='u')
  97.     {        
  98.         if (t[1]==':')
  99.         {
  100.              while(*t)
  101.                 t[3]=*t++;
  102.             t=(char*)pb->addrin[0];
  103.             t[3]=t[3]|32;
  104.         }else{
  105.             while(*t)
  106.                 t[5]=*t++;
  107.             t=(char*)pb->addrin[0];
  108.             t[1]=':';
  109.             t[2]='/';
  110.             t[3]=(char)Dgetdrv()+'a';
  111.         }
  112.         t[0]='u';
  113.     }
  114.  
  115.     for(; *t; t++)
  116.     {
  117.         if(*t=='\\')
  118.             *t='/';
  119.     }
  120.  
  121.     if (!Pdomain(-1))            /* For TOS domain programs, convert path to lower case */
  122.     {
  123.         for(t=(char*)pb->addrin[0]; *t; t++)
  124.         {
  125.             if((*t>='A')&&(*t<='Z'))
  126.                 *t|=32;
  127.         }
  128.         for(t=(char*)pb->addrin[1]; *t; t++)
  129.         {
  130.             if((*t>='A')&&(*t<='Z'))
  131.                 *t|=32;
  132.         }
  133.     }
  134.     DIAGS(("modified path=%s\n",(char*)pb->addrin[0]));
  135.     
  136.     fsel_owner=client;
  137.     fsel_pb=pb;
  138.     
  139.     open_fileselector((char*)pb->addrin[0], "", &handle_fsel, &cancel_fsel);
  140.     
  141.     Fread(client->clnt_pipe_rd,sizeof(unsigned long),&dummy_rtn);
  142.  
  143.     Psemaphore(3,FSELECT_SEMAPHORE,0L);        /* Release the file selector */
  144.  
  145.     return XAC_DONE;
  146. }
  147.  
  148. unsigned long XA_fsel_exinput(short clnt_pid, AESPB *pb)
  149. {
  150.     XA_CLIENT *client=Pid2Client(clnt_pid);
  151.     unsigned long dummy_rtn;
  152.     char *t;
  153.     
  154.     if (update_lock==clnt_pid)
  155.     {
  156.         update_cnt=0;
  157.         update_lock=FALSE;
  158.         Psemaphore(3,UPDATE_LOCK,0L);
  159.     }
  160.  
  161.     if (mouse_lock==clnt_pid)
  162.     {
  163.         mouse_cnt=0;
  164.         mouse_lock=FALSE;
  165.         Psemaphore(3,MOUSE_LOCK,0L);
  166.     }
  167.     
  168.     Psemaphore(2,FSELECT_SEMAPHORE,-1L);
  169.  
  170.     DIAGS(("fsel_exinput:title=%s,path=%s,file=%s\n",(char*)pb->addrin[2],(char*)pb->addrin[0],(char*)pb->addrin[1]));
  171.  
  172.     t=(char*)pb->addrin[0];
  173.     if ((t[1]==':')&&((t[0]|32)!='u'))
  174.     {
  175.         t[1]=t[0]|32;
  176.         t[0]='/';
  177.     }
  178.     
  179.     for(; *t; t++)
  180.     {
  181.         if(*t=='\\')
  182.             *t='/';
  183.     }
  184.  
  185.     if (!Pdomain(-1))            /* For TOS domain programs, convert path to lower case */
  186.     {
  187.         for(t=(char*)pb->addrin[0]; *t; t++)
  188.         {
  189.             if((*t>='A')&&(*t<='Z'))
  190.                 *t|=32;
  191.         }
  192.         for(t=(char*)pb->addrin[1]; *t; t++)
  193.         {
  194.             if((*t>='A')&&(*t<='Z'))
  195.                 *t|=32;
  196.         }
  197.     }
  198.  
  199.     DIAGS(("modified path=%s\n",(char*)pb->addrin[0]));
  200.     
  201.     fsel_owner=client;
  202.     fsel_pb=pb;
  203.     
  204.     open_fileselector((char*)pb->addrin[0], (char*)pb->addrin[2], &handle_fsel, &cancel_fsel);
  205.     
  206.     Fread(client->clnt_pipe_rd,sizeof(unsigned long),&dummy_rtn);
  207.  
  208.     Psemaphore(3,FSELECT_SEMAPHORE,-1L);
  209.  
  210.     return XAC_DONE;
  211. }
  212.